#pragma once
#include "Core.h"
#include "msg.h"
#include "block.h"

class IMemoryStrategy
{
public:
	virtual struct block* alloc_block()=0;
	virtual void		  free_block(struct block*&)=0;
	virtual	struct msg*	  alloc_msg()=0;
	virtual void		  free_msg(struct msg*&)=0;
	virtual	void		  force_free_block(struct block*) = 0;
	virtual void		  force_free_msg(struct msg*) = 0;
};

class CLimitedCacheMemory:public IMemoryStrategy,public CObject
{
public:
	CLimitedCacheMemory(uint32 max_msg_size,uint32 max_block_size);

	virtual struct block* alloc_block();
	virtual void		  free_block(struct block*&);
	virtual	struct msg*	  alloc_msg();
	virtual void		  free_msg(struct msg*&);
	virtual	void		  force_free_block(struct block*);
	virtual void		  force_free_msg(struct msg*);
private:
	uint32 max_msg_size_;
	uint32 cur_msg_size_;
	uint32 cur_msg_count_;

	uint32 max_block_size_;
	uint32 cur_block_size_;
	uint32 cur_block_count_;
};